//
// Write a function that takes a string as input and returns
// the string reversed.
//
// Example:
// Given s = "hello", return "olleh".
//

class Solution {
    // Time:  O(n)
    // Space: O(1)
    func reverseString(s: String) -> String {
        var chars = Array(s.characters)
        var i = chars.startIndex
        var j = chars.endIndex - 1

        while i < j {
            swap(&chars[i], &chars[j])
            i += 1
            j -= 1
        }
        return String(chars)
    }
}

class Solution2 {
    // Time:  O(n)
    // Space: O(1)
    func reverseString(s: String) -> String {
        return String(s.characters.reversed())
    }
}
